<?php

/**
 * Helper to implementation of hook_content_default_fields().
 */
function _news_publishing_content_default_fields() {
  $fields = array();

  // Exported field: field_source
  $fields[] = array(
    'field_name' => 'field_source',
    'type_name' => 'news',
    'display_settings' => array(
      'weight' => '3',
      'parent' => '',
      'token' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      '4' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'label' => array(
        'format' => 'above',
      ),
      'teaser' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'full' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
    'widget_active' => '1',
    'type' => 'text',
    'required' => '0',
    'multiple' => '1',
    'module' => 'text',
    'active' => '1',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'widget' => array(
      'rows' => 5,
      'size' => '60',
      'default_value' => array(
        '0' => array(
          'value' => '',
          '_error_element' => 'default_value_widget][field_source][0][value',
        ),
      ),
      'default_value_php' => NULL,
      'label' => 'Source',
      'weight' => '3',
      'description' => 'Sources used in the creation of this item.',
      'type' => 'text_textfield',
      'module' => 'text',
    ),
  );

  // Exported field: field_workflow_has_sched_change
  $fields[] = array(
    'field_name' => 'field_workflow_has_sched_change',
    'type_name' => 'news',
    'display_settings' => array(
      'weight' => '5',
      'parent' => '',
      'token' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      '4' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'label' => array(
        'format' => 'above',
      ),
      'teaser' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'full' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
    'widget_active' => '1',
    'type' => 'text',
    'required' => '0',
    'multiple' => '0',
    'module' => 'text',
    'active' => '1',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => 'Immediate
Scheduled',
    'allowed_values_php' => '',
    'widget' => array(
      'default_value' => array(
        '0' => array(
          'value' => NULL,
        ),
      ),
      'default_value_php' => NULL,
      'label' => 'Workflow has scheduled change',
      'weight' => '5',
      'description' => 'Do you want to schedule a change in state, as opposed to make a change immediately on saving?',
      'type' => 'optionwidgets_onoff',
      'module' => 'optionwidgets',
    ),
  );

  // Exported field: field_workflow_scheduled_state
  $fields[] = array(
    'field_name' => 'field_workflow_scheduled_state',
    'type_name' => 'news',
    'display_settings' => array(
      'weight' => '7',
      'parent' => '',
      'token' => array(
        'format' => 'default',
        'exclude' => 1,
      ),
      '4' => array(
        'format' => 'default',
        'exclude' => 1,
      ),
      'label' => array(
        'format' => 'above',
      ),
      'teaser' => array(
        'format' => 'default',
        'exclude' => 1,
      ),
      'full' => array(
        'format' => 'default',
        'exclude' => 1,
      ),
    ),
    'widget_active' => '1',
    'type' => 'text',
    'required' => '0',
    'multiple' => '0',
    'module' => 'text',
    'active' => '1',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'widget' => array(
      'rows' => 5,
      'size' => '60',
      'default_value' => array(
        '0' => array(
          'value' => '',
          '_error_element' => 'default_value_widget][field_workflow_scheduled_state][0][value',
        ),
      ),
      'default_value_php' => NULL,
      'label' => 'Workflow scheduled state',
      'weight' => '7',
      'description' => '',
      'type' => 'text_textfield',
      'module' => 'text',
    ),
  );

  // Exported field: field_workflow_scheduled_time
  $fields[] = array(
    'field_name' => 'field_workflow_scheduled_time',
    'type_name' => 'news',
    'display_settings' => array(
      'weight' => '6',
      'parent' => '',
      'token' => array(
        'format' => 'field_workflow_scheduled_time_long',
        'exclude' => 0,
      ),
      '4' => array(
        'format' => 'field_workflow_scheduled_time_long',
        'exclude' => 0,
      ),
      'label' => array(
        'format' => 'above',
      ),
      'teaser' => array(
        'format' => 'field_workflow_scheduled_time_long',
        'exclude' => 0,
      ),
      'full' => array(
        'format' => 'field_workflow_scheduled_time_long',
        'exclude' => 0,
      ),
    ),
    'widget_active' => '1',
    'type' => 'date',
    'required' => '0',
    'multiple' => '0',
    'module' => 'date',
    'active' => '1',
    'granularity' => array(
      'year' => 'year',
      'month' => 'month',
      'day' => 'day',
      'hour' => 'hour',
      'minute' => 'minute',
    ),
    'timezone_db' => 'UTC',
    'tz_handling' => 'site',
    'todate' => '',
    'repeat' => 0,
    'repeat_collapsed' => '',
    'default_format' => 'field_workflow_scheduled_time_long',
    'widget' => array(
      'default_value' => 'blank',
      'default_value_code' => '',
      'default_value2' => 'same',
      'default_value_code2' => '',
      'input_format' => 'd.m.Y - H:i',
      'input_format_custom' => '',
      'increment' => '1',
      'text_parts' => array(),
      'year_range' => '-0:+3',
      'label_position' => 'above',
      'label' => 'Workflow scheduled time',
      'weight' => '6',
      'description' => 'Time to schedule the workflow state change.',
      'type' => 'date_popup',
      'module' => 'date',
    ),
  );

  // Exported field: field_workflow_state
  $fields[] = array(
    'field_name' => 'field_workflow_state',
    'type_name' => 'news',
    'display_settings' => array(
      'weight' => '4',
      'parent' => '',
      'token' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      '4' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'label' => array(
        'format' => 'above',
      ),
      'teaser' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
      'full' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
    'widget_active' => '1',
    'type' => 'text',
    'required' => '1',
    'multiple' => '0',
    'module' => 'text',
    'active' => '1',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => 'global $user;
$roles = $user->roles;

$node=node_load(arg(1));
$state = $node->field_workflow_state[0][\'value\'];

$options = array();

if (in_array(\'author_role\', $roles)) {
  if (!$state) {
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
  }
  if ($state ==\'Idea\') {
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Seed\') {
    $options[\'Seed\'] = t(\'Seed\');
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Draft\') {
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'For Review\') {
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Published\') {
    $options[\'Published\'] = t(\'Published\');
  }
  if ($state ==\'Promoted\') {
    $options[\'Promoted\'] = t(\'Promoted\');
  }
  if ($state ==\'Archived\') {
    $options[\'Archived\'] = t(\'Archived\');
  }
  if ($state ==\'Rejected\') {
    $options[\'Rejected\'] = t(\'Rejected\');
  }
}

if (in_array(\'editor\', $roles)) {
  if (!$state) {
    $options[\'Idea\'] = t(\'Seed\');
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
  }
  if ($state ==\'Idea\') {
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Seed\') {
    $options[\'Seed\'] = t(\'Seed\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Draft\') {
    $options[\'Seed\'] = t(\'Idea\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'For Review\') {
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Published\'] = t(\'Published\');
    $options[\'Promoted\'] = t(\'Promoted\');
    $options[\'Rejected\'] = t(\'Rejected\');
  }
  if ($state ==\'Published\') {
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Published\'] = t(\'Published\');
    $options[\'Promoted\'] = t(\'Promoted\');
  }
  if ($state ==\'Promoted\') {
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Published\'] = t(\'Published\');
    $options[\'Promoted\'] = t(\'Promoted\');
  }
  if ($state ==\'Archived\') {
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Archived\'] = t(\'Archived\');
  }
  if ($state ==\'Rejected\') {
    $options[\'Rejected\'] = t(\'Rejected\');
  }
}

if (in_array(\'site_manager\', $roles) || user_access(\'administer\')) {
    $options[\'Idea\'] = t(\'Idea\');
    $options[\'Seed\'] = t(\'Seed\');
    $options[\'Draft\'] = t(\'Draft\');
    $options[\'For Review\'] = t(\'For Review\');
    $options[\'Published\'] = t(\'Published\');
    $options[\'Promoted\'] = t(\'Promoted\');
    $options[\'Rejected\'] = t(\'Rejected\');
}

return $options;',
    'widget' => array(
      'default_value' => array(
        '0' => array(
          'value' => '',
        ),
      ),
      'default_value_php' => NULL,
      'label' => 'Workflow State',
      'weight' => '4',
      'description' => 'The current state of this node in the publishing workflow. ',
      'type' => 'optionwidgets_buttons',
      'module' => 'optionwidgets',
    ),
  );

  // Translatables
  array(
    t('Source'),
    t('Workflow State'),
    t('Workflow has scheduled change'),
    t('Workflow scheduled state'),
    t('Workflow scheduled time'),
  );

  return $fields;
}

/**
 * Helper to implementation of hook_rules_defaults().
 */
function _news_publishing_rules_defaults() {
  return array(
    'rules' => array(
      'news_publishing_1' => array(
        '#type' => 'rule',
        '#set' => 'rules_workflow_reject',
        '#label' => 'Set the workflow state to reject',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          '1' => 'news_publishing',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(),
        '#actions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Populate Content\'s field \'field_workflow_state\'',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Rejected',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_2' => array(
        '#type' => 'rule',
        '#set' => 'event_node_update',
        '#label' => 'Workflow state is for review',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#type' => 'condition',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'For Review',
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_field_has_value',
            '#info' => array(
              'label' => 'Workflow state is Seed',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#weight' => 0,
          ),
        ),
        '#actions' => array(
          '0' => array(
            '#info' => array(
              'label' => 'Notify all editors of item for review',
              'label callback' => FALSE,
              'module' => 'Node',
              'arguments' => array(
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'base' => 'rules_core_action_execute',
              'action_name' => 'action_email_role_send_email_action',
              'configurable' => TRUE,
            ),
            '#name' => 'rules_core_action_email_role_send_email_action',
            '#settings' => array(
              'recipient' => array(
                '5' => 5,
                '3' => 0,
                '4' => 0,
                '6' => 0,
              ),
              'subject' => '[For Review] %title',
              'message' => 'A new node of type %node_type has been posted for review on %site_name.

%node_url

%body',
              'node_types_set' => 'all',
              'node_types_selected' => array(
                'news' => 0,
                'page' => 0,
                'story' => 0,
              ),
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#type' => 'action',
            '#weight' => 0,
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_3' => array(
        '#type' => 'rule',
        '#set' => 'event_node_update',
        '#label' => 'Workflow state is published',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#weight' => 0,
            '#type' => 'condition',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Published',
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_field_has_value',
            '#info' => array(
              'label' => 'Workflow state is published',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
          ),
        ),
        '#actions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Send a mail to a user',
              'arguments' => array(
                'user' => array(
                  'type' => 'user',
                  'label' => 'Recipient',
                ),
              ),
              'module' => 'System',
              'eval input' => array(
                '0' => 'subject',
                '1' => 'message',
                '2' => 'from',
              ),
            ),
            '#name' => 'rules_action_mail_to_user',
            '#settings' => array(
              'from' => '',
              'subject' => '[Published] [node:title]',
              'message' => '[user:user],

Your item [node:title] on [user:site-name] has been published.

[node:site-url]/node/[node:nid]
',
              '#argument map' => array(
                'user' => 'author',
              ),
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'subject' => array(
                    '0' => 'node',
                  ),
                  'message' => array(
                    '0' => 'node',
                    '1' => 'user',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
          ),
          '1' => array(
            '#type' => 'action',
            '#settings' => array(
              'auto_save' => 1,
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#name' => 'rules_core_node_publish_action',
            '#info' => array(
              'label' => 'Publish updated content',
              'module' => 'Node',
              'arguments' => array(
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'base' => 'rules_core_action_execute',
              'action_name' => 'node_publish_action',
              'configurable' => FALSE,
              'label callback' => 'rules_core_node_label_callback',
              'label_skeleton' => 'Publish @node',
            ),
            '#weight' => 0,
          ),
          '2' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Remove updated content from front page',
              'module' => 'Node',
              'arguments' => array(
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'base' => 'rules_core_action_execute',
              'action_name' => 'node_unpromote_action',
              'configurable' => FALSE,
              'label callback' => 'rules_core_node_label_callback',
              'label_skeleton' => 'Remove @node from front page',
            ),
            '#name' => 'rules_core_node_unpromote_action',
            '#settings' => array(
              'auto_save' => 1,
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_4' => array(
        '#type' => 'rule',
        '#set' => 'event_node_update',
        '#label' => 'Workflow state is promoted',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#info' => array(
              'label' => 'Workflow state is Promoted',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_field_has_value',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Promoted',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'condition',
            '#weight' => 0,
          ),
        ),
        '#actions' => array(
          '0' => array(
            '#weight' => 0,
            '#type' => 'action',
            '#settings' => array(
              'from' => '',
              'subject' => '[Promoted] [node:title]',
              'message' => 'Congratulations [user:user],

Your item [node:title] has been promoted to the home page of [user:site-name].

[node:site-url]/node/[node:nid]
',
              '#argument map' => array(
                'user' => 'author',
              ),
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'subject' => array(
                    '0' => 'node',
                  ),
                  'message' => array(
                    '0' => 'node',
                    '1' => 'user',
                  ),
                ),
              ),
            ),
            '#name' => 'rules_action_mail_to_user',
            '#info' => array(
              'label' => 'Send a mail to a user',
              'arguments' => array(
                'user' => array(
                  'type' => 'user',
                  'label' => 'Recipient',
                ),
              ),
              'module' => 'System',
              'eval input' => array(
                '0' => 'subject',
                '1' => 'message',
                '2' => 'from',
              ),
            ),
          ),
          '1' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Publish updated content',
              'module' => 'Node',
              'arguments' => array(
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'base' => 'rules_core_action_execute',
              'action_name' => 'node_publish_action',
              'configurable' => FALSE,
              'label callback' => 'rules_core_node_label_callback',
              'label_skeleton' => 'Publish @node',
            ),
            '#name' => 'rules_core_node_publish_action',
            '#settings' => array(
              'auto_save' => 1,
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#type' => 'action',
          ),
          '2' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Promote updated content to front page',
              'module' => 'Node',
              'arguments' => array(
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'base' => 'rules_core_action_execute',
              'action_name' => 'node_promote_action',
              'configurable' => FALSE,
              'label callback' => 'rules_core_node_label_callback',
              'label_skeleton' => 'Promote @node to front page',
            ),
            '#name' => 'rules_core_node_promote_action',
            '#settings' => array(
              'auto_save' => 1,
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_5' => array(
        '#type' => 'rule',
        '#set' => 'event_node_update',
        '#label' => 'Workflow state is draft',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#type' => 'condition',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Draft',
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_field_has_value',
            '#info' => array(
              'label' => 'Workflow state is Draft',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#weight' => 0,
          ),
        ),
        '#actions' => array(),
        '#version' => 6003,
      ),
      'news_publishing_6' => array(
        '#type' => 'rule',
        '#set' => 'rules_scheduled_workflow_state_change',
        '#label' => 'Perform state change',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Content\'s field \'field_workflow_has_sched_change\' has value',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_field_has_value',
            '#settings' => array(
              'field_name' => 'field_workflow_has_sched_change',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Scheduled',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'condition',
          ),
        ),
        '#actions' => array(
          '4' => array(
            '#weight' => -10,
            '#info' => array(
              'label' => 'Set workflow state to the scheduled state change',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Idea',
                ),
              ),
              'code' => 'return array(
  0 => array(\'value\' => \'[node:field_workflow_scheduled_state-raw]\'),
);',
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'code' => array(
                    '0' => 'node',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
          ),
          '1' => array(
            '#info' => array(
              'label' => 'Deselect scheduled state flag',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_has_sched_change',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Immediate',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
            '#weight' => 0,
          ),
          '2' => array(
            '#weight' => 0,
            '#type' => 'action',
            '#settings' => array(
              'field_name' => 'field_workflow_scheduled_time',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => NULL,
                  'value2' => NULL,
                  'timezone' => NULL,
                  'offset' => NULL,
                  'offset2' => NULL,
                  'rrule' => NULL,
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#info' => array(
              'label' => 'Set scheduled time to blank',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
              ),
              'module' => 'CCK',
            ),
          ),
          '3' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Set workflow state change to blank',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_scheduled_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => '',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_7' => array(
        '#type' => 'rule',
        '#set' => 'event_node_update',
        '#label' => 'Schedule workflow state change',
        '#active' => 1,
        '#weight' => '-10',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Created content is News',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'module' => 'Node',
            ),
            '#name' => 'rules_condition_content_is_type',
            '#settings' => array(
              'type' => array(
                'news' => 'news',
              ),
              '#argument map' => array(
                'node' => 'node',
              ),
            ),
            '#type' => 'condition',
          ),
          '1' => array(
            '#type' => 'condition',
            '#settings' => array(
              'field_name' => 'field_workflow_has_sched_change',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Scheduled',
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_field_has_value',
            '#info' => array(
              'label' => 'Created content\'s field \'field_workflow_has_sched_change\' has value',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#weight' => 0,
          ),
        ),
        '#actions' => array(
          '3' => array(
            '#type' => 'action',
            '#settings' => array(
              'severity' => '5',
              'type' => 'rules',
              'message' => 'workflow state is: [node:field_workflow_state-raw]',
              'link' => '',
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'message' => array(
                    '0' => 'node',
                  ),
                ),
              ),
            ),
            '#name' => 'rules_action_watchdog',
            '#info' => array(
              'label' => 'Log to watchdog',
              'module' => 'System',
              'eval input' => array(
                '0' => 'type',
                '1' => 'message',
                '2' => 'link',
              ),
            ),
            '#weight' => -10,
          ),
          '0' => array(
            '#weight' => -9,
            '#info' => array(
              'label' => 'Move new state into scheduled state field',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_scheduled_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => '[node:field_workflow_state-raw]',
                ),
              ),
              'code' => '',
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'value|0|value' => array(
                    '0' => 'node',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
          ),
          '1' => array(
            '#weight' => -8,
            '#info' => array(
              'label' => 'Make current state represent the actual current state (rather the the scheduled state)',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Idea',
                ),
              ),
              'code' => 'return array(
  0 => array(\'value\' => \'[node_unchanged:field_workflow_state-raw]\'),
);',
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'code' => array(
                    '0' => 'node_unchanged',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
          ),
          '2' => array(
            '#info' => array(
              'arguments' => array(
                'task_identifier' => array(
                  'type' => 'string',
                  'label' => 'Identifier',
                  'description' => 'User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced.',
                ),
                'task_date' => array(
                  'type' => 'date',
                  'label' => 'Scheduled evaluation date',
                ),
                'node' => array(
                  'label' => 'Content',
                  'type' => 'node',
                ),
              ),
              'label' => 'Schedule "Perform scheduled workflow state change"',
              'status' => 'custom',
              'categories' => array(
                '0' => 'Workflow',
              ),
              'module' => 'Rule Scheduler',
              'base' => 'rules_scheduler_action',
              'set' => 'rules_scheduled_workflow_state_change',
            ),
            '#name' => 'rules_action_schedule_set_rules_scheduled_workflow_state_change',
            '#settings' => array(
              'task_identifier' => 'Scheduled state change for [node:nid]',
              'task_date' => '[node:field_workflow_scheduled_time-datetime]',
              '#argument map' => array(
                'node' => 'node',
              ),
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'task_identifier' => array(
                    '0' => 'node',
                  ),
                  'task_date' => array(
                    '0' => 'node',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
            '#weight' => 0,
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_8' => array(
        '#type' => 'rule',
        '#set' => 'rules_scheduled_workflow_state_change',
        '#label' => 'Perform state change',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Content\'s field \'field_workflow_has_sched_change\' has value',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_field_has_value',
            '#settings' => array(
              'field_name' => 'field_workflow_has_sched_change',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Scheduled',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'condition',
          ),
        ),
        '#actions' => array(
          '4' => array(
            '#weight' => -10,
            '#info' => array(
              'label' => 'Set workflow state to the scheduled state change',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Idea',
                ),
              ),
              'code' => 'return array(
  0 => array(\'value\' => \'[node:field_workflow_scheduled_state-raw]\'),
);',
              '#eval input' => array(
                'token_rules_input_evaluator' => array(
                  'code' => array(
                    '0' => 'node',
                  ),
                ),
              ),
            ),
            '#type' => 'action',
          ),
          '1' => array(
            '#info' => array(
              'label' => 'Deselect scheduled state flag',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_has_sched_change',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Immediate',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
            '#weight' => 0,
          ),
          '2' => array(
            '#weight' => 0,
            '#type' => 'action',
            '#settings' => array(
              'field_name' => 'field_workflow_scheduled_time',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => NULL,
                  'value2' => NULL,
                  'timezone' => NULL,
                  'offset' => NULL,
                  'offset2' => NULL,
                  'rrule' => NULL,
                ),
              ),
              'code' => '',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#info' => array(
              'label' => 'Set scheduled time to blank',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
              ),
              'module' => 'CCK',
            ),
          ),
          '3' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Set workflow state change to blank',
              'label callback' => FALSE,
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_scheduled_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => '',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
      'news_publishing_10' => array(
        '#type' => 'rule',
        '#set' => 'rules_workflow_reject',
        '#label' => 'Set the workflow state to reject',
        '#active' => 1,
        '#weight' => '0',
        '#categories' => array(
          '0' => 'Workflow',
          '1' => 'news_publishing',
          'news_publishing' => 'news_publishing',
        ),
        '#status' => 'default',
        '#conditions' => array(),
        '#actions' => array(
          '0' => array(
            '#weight' => 0,
            '#info' => array(
              'label' => 'Populate Content\'s field \'field_workflow_state\'',
              'arguments' => array(
                'node' => array(
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'eval input' => array(
                '0' => 'code',
                '1' => 'value|0|value',
              ),
              'module' => 'CCK',
            ),
            '#name' => 'content_rules_action_populate_field',
            '#settings' => array(
              'field_name' => 'field_workflow_state',
              '#argument map' => array(
                'node' => 'node',
              ),
              'value' => array(
                '0' => array(
                  'value' => 'Rejected',
                ),
              ),
              'code' => '',
            ),
            '#type' => 'action',
          ),
        ),
        '#version' => 6003,
      ),
    ),
    'rule_sets' => array(
      'rules_workflow_reject' => array(
        'arguments' => array(
          'node' => array(
            'label' => 'Content',
            'type' => 'node',
          ),
        ),
        'label' => 'Set workflow state to reject',
        'status' => 'default',
        'categories' => array(
          '0' => 'Workflow',
          '1' => 'news_publishing',
          'news_publishing' => 'news_publishing',
        ),
      ),
      'rules_scheduled_workflow_state_change' => array(
        'arguments' => array(
          'node' => array(
            'label' => 'Content',
            'type' => 'node',
          ),
        ),
        'label' => 'Perform scheduled workflow state change',
        'status' => 'default',
        'categories' => array(
          '0' => 'Workflow',
          'news_publishing' => 'news_publishing',
        ),
      ),
    ),
  );
}

/**
 * Helper to implementation of hook_user_default_permissions().
 */
function _news_publishing_user_default_permissions() {
  $permissions = array();

  // Exported permission: access all views
  $permissions[] = array(
    'name' => 'access all views',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: access content
  $permissions[] = array(
    'name' => 'access content',
    'roles' => array(
      '0' => 'anonymous user',
      '1' => 'authenticated user',
      '2' => 'author_role',
      '3' => 'editor',
      '4' => 'site_manager',
      '5' => 'speaker',
    ),
  );

  // Exported permission: access service links
  $permissions[] = array(
    'name' => 'access service links',
    'roles' => array(
      '0' => 'anonymous user',
      '1' => 'authenticated user',
      '2' => 'author_role',
      '3' => 'editor',
      '4' => 'site_manager',
    ),
  );

  // Exported permission: administer content types
  $permissions[] = array(
    'name' => 'administer content types',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: administer date tools
  $permissions[] = array(
    'name' => 'administer date tools',
    'roles' => array(),
  );

  // Exported permission: administer languages
  $permissions[] = array(
    'name' => 'administer languages',
    'roles' => array(),
  );

  // Exported permission: administer nodes
  $permissions[] = array(
    'name' => 'administer nodes',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: administer pathauto
  $permissions[] = array(
    'name' => 'administer pathauto',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: administer service links
  $permissions[] = array(
    'name' => 'administer service links',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: administer views
  $permissions[] = array(
    'name' => 'administer views',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: create news content
  $permissions[] = array(
    'name' => 'create news content',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
      '3' => 'speaker',
    ),
  );

  // Exported permission: delete any news content
  $permissions[] = array(
    'name' => 'delete any news content',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: delete own news content
  $permissions[] = array(
    'name' => 'delete own news content',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: edit any news content
  $permissions[] = array(
    'name' => 'edit any news content',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
    ),
  );

  // Exported permission: edit field_source
  $permissions[] = array(
    'name' => 'edit field_source',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
    ),
  );

  // Exported permission: edit field_workflow_has_sched_change
  $permissions[] = array(
    'name' => 'edit field_workflow_has_sched_change',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: edit field_workflow_scheduled_state
  $permissions[] = array(
    'name' => 'edit field_workflow_scheduled_state',
    'roles' => array(),
  );

  // Exported permission: edit field_workflow_scheduled_time
  $permissions[] = array(
    'name' => 'edit field_workflow_scheduled_time',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: edit field_workflow_state
  $permissions[] = array(
    'name' => 'edit field_workflow_state',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
    ),
  );

  // Exported permission: edit own news content
  $permissions[] = array(
    'name' => 'edit own news content',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
      '3' => 'speaker',
    ),
  );

  // Exported permission: notify of path changes
  $permissions[] = array(
    'name' => 'notify of path changes',
    'roles' => array(
      '0' => 'site_manager',
    ),
  );

  // Exported permission: revert revisions
  $permissions[] = array(
    'name' => 'revert revisions',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
    ),
  );

  // Exported permission: translate interface
  $permissions[] = array(
    'name' => 'translate interface',
    'roles' => array(),
  );

  // Exported permission: view date repeats
  $permissions[] = array(
    'name' => 'view date repeats',
    'roles' => array(),
  );

  // Exported permission: view field_source
  $permissions[] = array(
    'name' => 'view field_source',
    'roles' => array(
      '0' => 'anonymous user',
      '1' => 'authenticated user',
      '2' => 'author_role',
      '3' => 'editor',
      '4' => 'site_manager',
    ),
  );

  // Exported permission: view field_workflow_has_sched_change
  $permissions[] = array(
    'name' => 'view field_workflow_has_sched_change',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: view field_workflow_scheduled_state
  $permissions[] = array(
    'name' => 'view field_workflow_scheduled_state',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: view field_workflow_scheduled_time
  $permissions[] = array(
    'name' => 'view field_workflow_scheduled_time',
    'roles' => array(
      '0' => 'editor',
      '1' => 'site_manager',
    ),
  );

  // Exported permission: view field_workflow_state
  $permissions[] = array(
    'name' => 'view field_workflow_state',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
    ),
  );

  // Exported permission: view revisions
  $permissions[] = array(
    'name' => 'view revisions',
    'roles' => array(
      '0' => 'author_role',
      '1' => 'editor',
      '2' => 'site_manager',
      '3' => 'speaker',
    ),
  );

  return $permissions;
}
